package com.myspring.spark;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

public class MySpark {
	private static final Integer NUM_SAMPLES = 20;

	public static void main(String[] args) {
		SparkConf conf = new SparkConf().setMaster("spark://192.168.126.21:7077").setAppName("my test");
		@SuppressWarnings("resource")
		JavaSparkContext sc = new JavaSparkContext(conf);
		sc.addJar("spark-demo-0.0.1-SNAPSHOT.jar");

		List<Integer> l = new ArrayList<Integer>(NUM_SAMPLES);
		for (int i = 0; i < NUM_SAMPLES; i++) {
			l.add(i);
		}
		JavaRDD<Integer> fileData = sc.parallelize(l).filter(new Function<Integer, Boolean>() {
			/**
			 * 
			 */
			private static final long serialVersionUID = -6803757082415302616L;

			public Boolean call(Integer i) {
				return true;
			}
		});
		Integer min = fileData.min( new Comparator1());
		Integer max = fileData.max( new Comparator1());
		System.out.println("最大值：" + max+"最小值"+min);

	}
}
class Comparator1 implements Serializable, Comparator<Integer>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2832638645192310185L;

	@Override
	public int compare(Integer o1, Integer o2) {
		return o1 - o2;
		}
	
}
